import java.util.Scanner;

public class demo01 {
    //Fibonacci数列
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a=0;
        int b=1;
        while (b<n){
            int c=a+b;
            a=b;
            b=c;
        }
        int num= Math.min((n - a), (b - n));
        System.out.println(num);
    }
}
